package com.sudo.boot.admin._sys.my;

import cn.hutool.core.lang.tree.Tree;
import com.sudo.boot.base.pojo.JsonRes;
import com.sudo.boot.satokensso.util.BootStpUtil;
import com.sudo.boot.service.sys.SysMenuService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("my-menu")
public class MyMenuController {

    @Resource
    private SysMenuService sysMenuService;


    /**
     * 获取我的角色菜单树状结构
     *
     * @return 系统菜单 树状结构
     */
    @GetMapping("selectMySysMenuTree")
    public JsonRes<List<Tree<String>>> selectMySysMenuTree() {
        String currRoleCode = BootStpUtil.getCurrRole();
        List<Tree<String>> treeList = sysMenuService.selectMenuTreeByRoleCode(currRoleCode);
        return JsonRes.ok(treeList);
    }

    /**
     * 获取模拟角色菜单树状结构
     *
     * @return 系统菜单 树状结构
     */
    @GetMapping("selectSimulateSysMenuTree")
    public JsonRes<List<Tree<String>>> selectSimulateSysMenuTree() {
        String currRoleCode = BootStpUtil.getCurrRole();
        List<Tree<String>> treeList = sysMenuService.selectSimulateMenuTreeByRoleCode(currRoleCode);
        return JsonRes.ok(treeList);
    }

    /**
     * 获取角色的权限按钮
     *
     * @return 系统菜单 List
     */
    @GetMapping("getRoleButtonList")
    public JsonRes<List<String>> getRoleButtonList() {
        String currRoleCode = BootStpUtil.getCurrRole();
        List<String> buttonList = sysMenuService.getRoleButtonList(currRoleCode);
        return JsonRes.ok(buttonList);
    }

}
